package com.jz.beijianbao.legalPersonPlant.controller;


import com.jz.beijianbao.legalPersonPlant.bean.LegalPlant;
import com.jz.beijianbao.legalPersonPlant.bean.PlantSelectVo;
import com.jz.beijianbao.legalPersonPlant.bean.UpdateEnabledVo;
import com.jz.beijianbao.legalPersonPlant.bean.UpdatePlantVo;
import com.jz.beijianbao.legalPersonPlant.service.LegalPlantService;
import com.jz.util.ResultBuildVO;
import com.jz.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


@RestController
@CrossOrigin
public class TestLegalPlant {

    @Autowired
    private LegalPlantService legalPlantService;

    //法人下拉
    /*@GetMapping("legalPerson/ofCurrentUser")
    public ResultVO queryXiaLa(Integer id){
        return legalPlantService.queryPerson(id);
    }*/


    //分页查询
    @PostMapping("legalPlant/query")
    public ResultVO queryPage(@RequestBody PlantSelectVo plantSelectVo){
        ResultVO resultVO = legalPlantService.queryPag(plantSelectVo);
        return resultVO;

    }

    //新增
    @PostMapping("legalPlant/add")
    public ResultVO add(@RequestBody LegalPlant legalPlant){
        ResultVO resultVO = legalPlantService.add(legalPlant);
        return resultVO;
    }


    //修改
    @PostMapping("legalPlant/update")
    public ResultVO update(@RequestBody @Valid UpdatePlantVo updatePlantVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVO.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return legalPlantService.updatePlant(updatePlantVo);

    }


    //启用禁用
    @PostMapping("legalPlant/updatestatus")
    public ResultVO updatestatus(@RequestBody @Valid UpdateEnabledVo updateEnabledVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuildVO.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return legalPlantService.updateStatus(updateEnabledVo);

    }














}
